﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Data;
using System.Data.Entity;
using System.Data.Entity.Infrastructure;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Models
{
    public class RoomTypeBussiness: IDbServices<bool,int,TblRoomType>
    {
        BookingDB db = new BookingDB();
       

        public bool AddData(TblRoomType e)
        {
            try
            {
                
                db.TblRoomTypes.Add(e);
                db.SaveChanges();
                return true;
            }
            catch (Exception ex)
            {
                Console.Write(ex.Message);
                return false;
            }
            

        }

        public bool UpdateData(TblRoomType e)
        {
            try
            {
               
                db.Entry(e).State = EntityState.Modified;
                db.SaveChanges();
                return true;
            }
            catch (ValidationException ex)
            {

                return false;
            }
        }

        public bool DeleteData(int key)
        {
            TblRoomType objRoomType = new TblRoomType();
            objRoomType = db.TblRoomTypes.Find(key);
            try
            {
                db.TblRoomTypes.Remove(objRoomType);
                db.SaveChanges();
                return true;

            }
            catch (DbUpdateConcurrencyException)
            {

                return false;
            }
         
        }

        public TblRoomType GetDataByKey(int k)
        {
            try
            {
                return db.TblRoomTypes.Find(k);
            }
            catch (Exception)
            {

                return null;
            }
        }

        public List<TblRoomType> GetAll()
        {
            try
            {
                return db.TblRoomTypes.ToList<TblRoomType>();
            }
            catch (Exception)
            {

                return null;
            }
        }
    }
}
